from django.template import Library
from django.conf import settings
import copy

register = Library()


@register.inclusion_tag('menu.html')
def menu_list(request):
    info_dict = request.session.get('user_info')

    role = info_dict['role']

    # 获取当前用户的角色
    user_menu_list = copy.deepcopy(settings.UNICOM_MENU[role])

    # [{'text': '用户管理', 'url': '/user/'}, {'text': '订单管理', 'url': '/order/'},{'text': '工作管理', 'url': '/work/'}]
    # print(role)
    for row in user_menu_list:
        if request.path_info.startswith(row['url']):
            row['class'] = "active"

    return {'user_menu_list': user_menu_list}
